Przykad 7.3. Realizacja wyszukiwania w gb
public Solution search(INode initial, INode goal) {
   // Jeli ustawienie pocztkowe (initial) stanowi cel (goal), to wyjd
   if (initial.equals(goal)) { return new Solution (initial, goal); }

   INodeSet open = StateStorageFactory.create(OpenStateFactory.STACK);
   open.insert(initial.copy());

   // Stany, ktre ju odwiedzilimy
   INodeSet closed = StateStorageFactory.create(OpenStateFactory.HASH);
   while (!open.isEmpty()) {
      INode n = open.remove();
      closed.insert(n);

      DepthTransition trans = (DepthTransition) n.storedData();

      // Tumacz wszystkie nastpne ruchy na dodane stany OPEN (otwarte)
      DoubleLinkedList<IMove> moves = n.validMoves();
      for (Iterator<IMove> it = moves.iterator(); it.hasNext(); ) {
         IMove move = it.next();

         // Wykonaj ruch na kopii, poniewa dziaamy na zbiorach stanw planszy
         INode successor = n.copy();
         move.execute(successor);

         // Jeli ju odwiedzony, wyprbuj inny stan
         if (closed.contain(successor) != null) { continue; }

         int depth = 1;
         if (trans != null) { depth = trans.depth+1; }

         // Zapisz poprzedni ruch, eby mie lad rozwizania. Jeli
         // znaleziono rozwizanie, to wyjd, w przeciwnym razie dodaj
         // do zbioru OPEN, jeli nie przekroczono granicy gbokoci
         successor.storedData(new DepthTransition(move, n, depth));
         if (successor.equals(goal)) {
            return new Solution (initial, successor);
         }
         if (depth < depthBound) { open.insert(successor); }
      }
   }
   return new Solution (initial, goal, false);  // Nie ma rozwizania
}
